<?php
Globals::requireController('Admin');
Globals::requireTable('Serve');

class ServeController extends AdminController
{
    protected $ServeTable;
    
	public function __construct($config = null)
	{
		parent::__construct($config, true);
		$this->ServeTable = new ServeTable($config);
	}
	
	public function listAction(){
	    $where = array();
	    $count = $this->ServeTable->listCount($where);
	    $pageSize = 20;
	    $pageId	= $this->getIntParam('page');
	    $this->view->paging = $this->getPaging($count, $pageSize,$pageId);
	    $this->view->data = $this->ServeTable->listPage($where, 'id ASC', $pageSize, $pageId);
	    
	}
	
	public function editAction()
	{
	    $id = $this->getIntParam('id');
	    if($id > 0){
	        $title = $this->ServeTable->getRow($id);
	        if($title['id'] > 0){
	            $this->view->data = $title;
	        }
	    }
	    
	}
	
	public function doeditAction()
	{
	    $id = $this->getIntParam('id');
	    $data['gridcolor'] = $this->getParam('gridcolor');
	    $data['gridtag'] = $this->getParam('gridtag');
	    $data['gridicon'] = $this->getParam('gridicon');
	    $data['gridtitle'] = $this->getParam('gridtitle');
	    $data['gridurl'] = $this->getParam('gridurl');
	    $data['machine_type'] = $this->getIntParam('machine_type');
	    $data['createdate'] = date('Y-m-d H:i:s');
	    if($id > 0){
	        $this->ServeTable->update($data,$id);
	    }else{
	        $this->ServeTable->add($data);
	    }
	    $this->redirectToAction('list');
	    exit();
	}
	
	public function deleteAction()
	{
	    $id = $this->getIntParam('id');
	    $this->ServeTable->delete($id);
	    $this->redirectToAction('list');
	    exit();
	}
	
}
